<template>
  <div>
    <el-button type="primary" @click="dialogFormVisible = true">点击添加</el-button>
    <el-dialog title="点击添加" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="名称" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="年龄" :label-width="formLabelWidth">
          <el-input v-model="form.age" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </div>
    </el-dialog>
    <div v-for="(item,index) in tableData" :key="index">
      <el-table border :data="item" style="width: 500px">
        <el-table-column prop="name" label="姓名">
        </el-table-column>
        <el-table-column prop="age" label="年龄">
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      dialogFormVisible: false,
      form: {
        name: "",
        age: ""
      },
      tableData: [
        [
          {
            name: "张三",
            age: "12"
          }
        ]
      ]
    };
  },
  methods: {
    add() {
      this.dialogFormVisible = false;
      this.tableData.push([JSON.parse(JSON.stringify(this.form))]);
    }
  }
};
</script>